/**
 * Copyright (C), 2015-2020, XXX有限公司
 * FileName: ProductContoller
 * Author:   sky
 * Date:     2020/4/14 15:39
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package cn.szh.controller;

import cn.szh.domain.Product;
import cn.szh.service.ProductService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author sky
 * @create 2020/4/14
 * @since 1.0.0
 */
@Controller
@RequestMapping("/product")
public class ProductContoller {
    @Autowired
    private ProductService productService;

    /**
     * 未分页
     * @return

    @RequestMapping("/findAll.do")
    public ModelAndView productList(){
        ModelAndView mv=new ModelAndView();
        List<Product> productList = productService.findAll();
        mv.addObject("productList",productList);
        mv.setViewName("product_list");
        return mv;
    }
     */
    /**
     * 分页代码
     * @return
     */
    @RequestMapping("/findAll.do")
    public ModelAndView productList(@RequestParam(name = "pageNum")Integer pageNum,@RequestParam(name = "pageSize")Integer pageSize){
        ModelAndView mv=new ModelAndView();
        List<Product> productList = productService.findAllByPage(pageNum,pageSize);
        PageInfo pageInfo=new PageInfo(productList);
        mv.addObject("pageInfo",pageInfo);
        mv.setViewName("product_list");
        return mv;
    }

    /**
     * 保存方法
     * @param product
     * @return
     */
    @RequestMapping("/save.do")
    public String save(Product product){
        productService.save(product);
        return "forward:findAll.do";
    }
}
